package com.twu.biblioteca;

/**
 * Created with IntelliJ IDEA.
 * User: mini server
 * Date: 9/20/13
 * Time: 1:24 AM
 * To change this template use File | Settings | File Templates.
 */
public class Book
{
    private String title;
    private String id;
    private int numOfAvailableCopies;

    public Book(String bookTitle, String book_id, int copiesAvailable){
        this.title = bookTitle;
        this.id = book_id;
        this.numOfAvailableCopies = copiesAvailable;
    }

    public boolean match(String id)
    {
        return this.id.equals(id);
    }

    public String getId()
    {
        return id;
    }

    public String display() {
        switch (numOfAvailableCopies)
        {
            case 0: return id + "-> " + title + ", Unavailable.";
            case 1: return id + "-> " + title + ", " + numOfAvailableCopies + " copy available.";
            default: return id + "-> " + title + ", " + numOfAvailableCopies + " copies available.";
        }
    }

    public boolean reserve()
    {
        numOfAvailableCopies--;
        return (numOfAvailableCopies + 1) > 0;
    }

    public boolean equals(Object obj)
    {
        if (obj == this)
        {
            return true;
        }

        if (getClass() != obj.getClass())
        {
            return false;
        }

        Book otherBook = (Book)obj;

        return title == otherBook.title && id == otherBook.id && numOfAvailableCopies == otherBook.numOfAvailableCopies;
    }
}
